
#include "lib_music.h"
//****************************************************************

#if 1
#define  CONFIG_MUSIC_PATH  "/home/music/"
#elif 0

#endif
//****************************************************************

static  pthread_t     lib_music_thread;
static  int           lib_music_index = 1;

static  file_list_t*  lib_music_list  = NULL;

static  music_para_t  lib_music_para;
//****************************************************************
int lib_music_play(int type)
{
	int ret = -1;

	char filename[1024] = {0};

	//****************************************************************
	
	memset(filename,0,sizeof(filename));
	//****************************************************************
#if 1
	if(file_list_get_filenum(lib_music_list) < 2){
		return -1;
	}

	srand(lib_music_index);
	lib_music_index = rand()%file_list_get_filenum(lib_music_list);
	
	ret = file_list_get_filename(lib_music_list,filename,lib_music_index);
#endif
	//****************************************************************
	if(ret != 0){
		return -1;
	}
	//****************************************************************
	log_i("i:t:n=%d:%d:%s\n",lib_music_index,file_list_get_filenum(lib_music_list),filename);
	//****************************************************************

	return 0;
}


//****************************************************************
void* lib_music_play_task(void *arg)
{
	int ret = -1;
	struct timeval timer;	

	while(1)
	{
		//****************************************************************
		usleep(1000);

		//****************************************************************

		//ret = lib_music_play(0);
		if(ret != 0){
			continue;
		}
		//****************************************************************
		timer.tv_sec  = 6;
		timer.tv_usec = 0;
		
		switch(select(0, NULL, NULL, NULL, &timer)) 
		{
		case -1:  
			log_e("Error!\n");
			break;
		case 0: 
			break;
		default:break;
		}
		
		//****************************************************************

		

		//****************************************************************
	}
}

//****************************************************************

int lib_music_init(void)
{
	int ret  = 0;
	
	log_i("lib image init.\n");
	
	file_list_create(&lib_music_list,CONFIG_MUSIC_PATH,MEDIA_TYPE_MUSIC,"./musicfile.list");
	if(!lib_music_list){
		log_e("image list error\n");
		return -1;
	}
	
	ret=pthread_create(&lib_music_thread, NULL, lib_music_play_task, NULL);
	if(ret != 0){
		log_e("thread error=%s\n",strerror(ret));
		return -1;
	}



	return 0;
}


int lib_music_deinit(void)
{

	



	return 0;
}

//****************************************************************

